<?php


namespace app\api\controller;


use app\common\controller\Api;
use app\api\model\UserAdminMessage as UserAdminMessageModel;

class UserAdminMessage extends Api
{

    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    /**
     * @var \app\admin\model\User
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new UserAdminMessageModel();
    }

    /**
     * 我的后台推送报告列表
     *
     */
    public function index()
    {
        $type = input('post.type');
        $limit = input('post.limit');

        $list = $this->model->where(['user_id'=>$this->auth->id,'type'=>$type])->where('content','neq','')->column('id,name,is_read');

        $this->success('请求成功',$list);
    }

    /*
     * 获取报告下面类型列表
     */
    public function sheetList()
    {
        $name = input('post.name');

        $type = input('post.type');

        $id = input('post.id');

        $list = $this->model->where(['id'=>$id])->group('sheet')->column('sheet');

        $this->success('请求成功',$list);

    }

    /*
     * 获取后台推送报告详情
     */
    public function messageDetail()
    {
        $name = input('post.name');
        $sheet = input('post.sheet');
        $type = input('post.type');
        $id = input('post.id');

        $list = $this->model::get(['id'=>$id]);
        $list->is_read = 2;
        $list->save();
        $this->success('请求成功',$list);
    }

    /*
     * 检测报告列表
     */
    public function reportList()
    {
        $list = $this->model->where(['user_id'=>$this->auth->id])->group('sheet')->column('sheet');

        $this->success('请求成功',$list);
    }

    /*
     * 检测报表下的消息列表
     */
    public function reportMessageList()
    {
        $sheet = input('post.sheet');

        $list = $this->model::where(['user_id'=>$this->auth->id,'sheet'=>$sheet])->where('content','neq','')->select();

        $this->success('请求成功',$list);
    }
}